
#include "thread_utils.h"



SingleThreadExecutor::SingleThreadExecutor()
    : m_running(true),
      m_thread([this]{_body();}) {}

void SingleThreadExecutor::_body()
{
    while (m_running) {
        m_queue.take()();
    }
}

void SingleThreadExecutor::exe(std::function<void(void)> action)
{
    m_queue.add(action);
}

void SingleThreadExecutor::stop()
{
    m_running = false;
}

void SingleThreadExecutor::join()
{
    m_thread.join();
}
